<template>
  <div>
    <div class="whole-xloop">
      <div class="title">当前上级</div>
      <template v-if="list.length>0">
        <div class="superior-list now-superior">
          <div class="avager"><img :src="parent.headimgurl"></div>
          <div class="superior">
            <div class="list-title">{{parent.nickname}}</div>
            <div class="order-title"> ID：{{parent.user_id}}</div>
          </div>
        </div>
        <div class="title">我的上级变动记录</div>
      </template>
      <van-list
        v-model="loading"
        :finished="finished"
        :error.sync="error"
        error-text="请求失败，点击重新加载"
        finished-text=""
        @load="onLoad"
      >
        <div class="superior-list" v-for="(item,index) in list" :key="index">
          <div class="avager"><img :src="item.headimgurl"></div>
          <div class="superior">
            <div class="list-title">{{item.nickname}}</div>
            <div class="order-title">上级ID：{{item.pid}}</div>
            <div class="order-title">绑定时间：{{item.create_time}}</div>
          </div>
        </div>
      </van-list>
    </div>
    <div v-if="list.length == 0 && finished">
      <no-data :noData="noData"></no-data>
    </div>
  </div>
</template>
<script>
import { LoopSuperior } from '@/api/user/xLoop/index'

import noData from '@/components/noData'
export default {
  components: {
    noData
  },
  data() {
    return {
      noData: {
        width: '240px',
        img: 'https://img.wifenxiao.com/h5-wfx/images/xloop/no-order-xloop-superior.png?v=1',
        text: '暂无上级',
        txtMarginTop: '0px'
      },
      parent: {},
      list: [],
      p: 1,
      loading: false,
      error: false,
      finished: false
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      // this.$loadingWrap.show()
      // setTimeout(() => {
      //   this.$loadingWrap.close()
      // }, 10000)
      LoopSuperior({ p: this.p }).then(res => {
        // this.$loadingWrap.close()
        this.finished = false
        this.loading = false
        if (res.status == 1) {
          this.parent = res.data.parent
          if (res.data && res.data.list.length > 0) {
            if (this.p == 1) {
              this.list = res.data.list
            } else {
              this.list.push(...res.data.list)
            }
            this.p++
          } else {
            this.finished = true
          }
        } else {
          this.$Error(res.msg)
        }
      })
    },
    // 加载更多
    onLoad() {
      // this.finished = false
      this.init()
    }
  }
}
</script>
<style lang="scss">

  .whole-xloop {
    padding: 0 16px;
    .superior-list  {
      display: flex;
      padding: 24px;
      background-color: #fff;
      border-radius: 12px;
      margin-bottom: 16px;
      .avager {
        img {
          width: 88px;
          height:88px;
          border-radius: 50%;
          object-fit: cover;
        }
      }
      .superior {
        margin-left: 16px;
        flex: 1;
      }
      .list-title {
        color: #333;
        font-size: 28px;
        font-weight: 500;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        overflow: hidden;
        line-height: 140%;
      }
      .order-title {
        margin-top: 8px;
        font-size: 24px;
        color: #333;
        line-height: 140%;
      }
      &.now-superior {
        background: linear-gradient(180deg, #FE754F 0%, #FD4149 100%);
        align-items: center;
        margin-bottom: 8px;
        .list-title {
          color: #fff;
        }
        .order-title {
          color: #fff
        }
      }
    }

  }
  .title {
    color: #333;
    font-size: 28px;
    font-weight: 500;
    padding: 16px 0;
    margin-left: 8px;
    line-height: 140%;
  }
  .no-data {
    padding: 72px 0!important;
  }

</style>